package org.itboys.core.controller.front.account;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;
import org.itboys.core.dto.account.SundayAccountDto;
import org.itboys.core.service.mongo.front.SundayFrontAccountService;
import org.itboys.core.util.AccountIdHoldUtils;
import org.itboys.core.util.ResponseMessage;
import org.itboys.framework.spring.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author：贾琦磊
 * @Date：2018/11/26
 * @Description：【供应商】银行卡
 */
@Controller
@RequestMapping("/sunday/mobile/account")
@Api(value = "account", description = "银行账号")
public class SundayMobileAccountController extends BaseController {
    @Autowired
    private SundayFrontAccountService accountService;

    @RequestMapping(value = "/save", method = {RequestMethod.POST})
    @ApiOperation(value = "新增")
    public void save(
            HttpServletRequest request,
            HttpServletResponse response,
            @ApiParam(value = "账号ID 新增时传0", required = true) @RequestParam(value = "accountId") Long accountId,
            @ApiParam(value = "银行卡类型  取key值为bank广告的副名称", required = true) @RequestParam(value = "bankType") Integer bankType,
            @ApiParam(value = "真实姓名", required = true) @RequestParam(value = "realName") String realName,
            @ApiParam(value = "手机号", required = true) @RequestParam(value = "mobile") String mobile,
            @ApiParam(value = "验证码", required = true) @RequestParam(value = "code") String code,
            @ApiParam(value = "卡号", required = true) @RequestParam(value = "number") String number
    ) {
        Long memberId = AccountIdHoldUtils.getMemberId();
        accountService.saveAccount(accountId, memberId, bankType, realName, mobile, code, number);
        ResponseMessage.success();
    }

    @RequestMapping(value = "/select", method = {RequestMethod.GET})
    @ApiOperation(value = "查找多个")
    public void select(
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        Long memberId = AccountIdHoldUtils.getMemberId();
        List<SundayAccountDto> result = accountService.selectAccount(memberId);
        ResponseMessage.success(result);
    }
}
